package com.example.myapplication;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.text.format.Formatter;

import java.io.File;

/**
 * 作者：Administrator
 * 2020/6/24
 */
public class AppInfo {
    private boolean open = false;
    public PackageInfo packageInfo;

    public AppInfo(PackageInfo packageInfo) {
        this.packageInfo = packageInfo;
    }

    public String getAppName(Context context) {
        PackageManager pm = context.getPackageManager();
        return packageInfo.applicationInfo.loadLabel(pm).toString();
    }

    public Drawable getIcon(Context context) {
        PackageManager pm = context.getPackageManager();
        Drawable icon = packageInfo.applicationInfo.loadIcon(pm);
        return icon;
    }

    public String getPath() {
        return packageInfo.applicationInfo.sourceDir;
    }

    public String getFileSizeString(Context context) {
        File file = new File(getPath());
        String fileSize = Formatter.formatFileSize(context, file.length());
        return fileSize;
    }

    public boolean isOpen() {
        return open;
    }

    public void setOpen(boolean open) {
        this.open = open;
    }
}
